import pythoncom, pyHook 
import os
import win32api, win32con
from win32api import GetSystemMetrics
import os.path
import ConfigParser
import time

config = ConfigParser.RawConfigParser()

def click(x,y):
    SCREEN_WIDTH = GetSystemMetrics (0)
    SCREEN_HEIGHT = GetSystemMetrics (1)
    #win32api.mouse_event(win32con.MOUSEEVENTF_MOVE | win32con.MOUSEEVENTF_ABSOLUTE, int(x/SCREEN_WIDTH*65535.0), int(y/SCREEN_HEIGHT*65535.0))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x , y, 0, 0)
#click(10,10)

if os.path.isfile("%s/config.cfg"%os.getcwd()):
   print 15 * "/"
   print "Config loaded..."
   print "Hack working properly..."
   print "MADE BY BRIX"
   print 15 * "/"
else:
   config.add_section('main')
   config.set('main', 'number_of_hits', '29')
   with open('config.cfg', 'wb') as configfile:
        config.write(configfile)
        print "Configuration file is created. Check 'config.cfg' in BRIX-HACK's folder."
        print 15 * "/"
        print "Config loaded..."
        print "Hack working properly..."
        print "MADE BY BRIX"
        print 15 * "/"


 
def OnKeyboardEvent(event):
    state = False
    #print 'Ime Poruke:',event.MessageName
    #print 'Poruka:',event.Message
    #print 'Vrijeme:',event.Time
    #print 'Window:',event.Window
    #print 'Ime Windowa:',event.WindowName
    #print 'Ascii:', event.Ascii, chr(event.Ascii)
    #print 'Tipka:', event.Key
    #print 'ID Tipke:', event.KeyID
    #print 'ScanCode:', event.ScanCode
    #print 'Extended:', event.Extended
    #print 'Injected:', event.Injected
    #print 'Alt', event.Alt
    #print 'Transition', event.Transition
    #print '---'
    if event.Key == "G":
       if event.WindowName.startswith("Minecraft"):
          if state == False:
             state = True
             print "SPAM-HIT Hack ON"
             #open("%s/CreativePoints/Data/plotovi.yml"%pluginlokacija2, 'r+')
             config.read('%s/config.cfg'%os.getcwd())
             number = config.getint('main', 'number_of_hits')
             for x in xrange(number):
                 time.sleep(0.1)
                 click(0, 0)
          elif state == True:
              print "SPAM-HIT Hack OFF"
              state = False
 
# return True to pass the event to other handlers
    return True
 
# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()
